package com.yn.front.zy;


import com.yn.common.page.BasePage;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.request.zy.OrganDepartmentQueryRequest;
import com.yn.common.request.zy.OrganDepartmentRequest;
import com.yn.common.response.sc.BaseResult;
import com.yn.common.response.zy.OrganDepartmentTreeResponse;
import com.yn.service.service.IOrganDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 医院科室 前端控制器
 * </p>
 *
 * @author xuquanjun
 * @since 2025-07-10
 */
@RestController
@RequestMapping("/api/front/department")
@Api(tags = "医院科室——用户端")
@Slf4j
public class OrganDepartmentController {

    @Autowired
    private IOrganDepartmentService departmentService;

    /**
     * 获取科室树状图
     * @return List<OrganDepartmentTreeResponse> 科室树状图
     */
    @ApiOperation(value = "获取tree结构的列表")
    @RequestMapping(value = "/list/tree", method = RequestMethod.GET)
    public BaseResult<List<OrganDepartmentTreeResponse>> getListTree() {
        return BaseResult.success(departmentService.getListTree());
    }


    /**
     * 获取科室信息分页列表
     * @param request 查询条件
     * @param pageRequest 分页条件
     * @return BaseResult<BasePage<OrganDepartmentDTO>>
     */
    @ApiOperation(value = "获取分页列表")
    @RequestMapping(value = "/list/page", method = RequestMethod.GET)
    public BaseResult<BasePage<OrganDepartmentTreeResponse>> getPageList(OrganDepartmentQueryRequest request, PageParamRequest pageRequest) {
        log.info("获取科室的分页列表入参,OrganDepartmentQueryRequest:{},PageParamRequest:{}",request,pageRequest);

        return BaseResult.success(BasePage.restPage(departmentService.getPageList(request, pageRequest)));
    }

    /**
     * 获取科室详情
     * @param id Integer 科室id
     * @return BaseResult<OrganDepartment> 科室详情
     */
    @GetMapping("/detail")
    @ApiOperation(value = "查询医院科室信息详情")
    public BaseResult<OrganDepartmentTreeResponse> getInfoById(@RequestParam @NotNull Integer id) {
        log.info("查询医院科室信息入参,{}",id);
        return BaseResult.success(departmentService.getInfoById(id));
    }


}
